**# Bookmark #1 Setting

*Windows
global root  = "G:/Dropbox/Environmental Injustice/Empirical"
global rawdata = "$root/rawdata"
global workdata = "$root/workdata"
global results = "$root/results"
global outfile = "$root/outfile"

cd "$workdata"

**# Bookmark #2 Firm Emission

*beta and sigma
foreach n in belowhs belowcl rural occupation{

use "$outfile/Firm_regression.dta",clear

forvalues i=2001/2010{
gen nf`i'=1 if year==`i'
replace nf`i'=0 if year~=`i'
gen belowhs_Year`i'=belowhs*nf`i'
gen belowcl_Year`i'=belowcl*nf`i'
gen rural_Year`i'=rural*nf`i'
gen occupation_Year`i'=occupation*nf`i'
}

reghdfe codemission `n'_Year2001 `n'_Year2002 `n'_Year2003 `n'_Year2004 `n'_Year2006 `n'_Year2007 `n'_Year2008 `n'_Year2009 `n'_Year2010,absorb(i.id i.province#i.year) cluster(i.province i.year)

clear
matrix beta = e(b)
svmat beta
keep beta1-beta9
keep in 1
export delimited using "$results/Table S14_Firm_`n'_beta.csv", replace

clear
matrix sigma = e(V)
svmat sigma
keep sigma1-sigma9
keep in 1 / 9
export delimited using "$results/Table S14_Firm_`n'_sigma.csv", replace
}